package com.ogawa.a7517.widget;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.Window;

import androidx.annotation.NonNull;

import com.ogawa.a7517.Constant;
import com.ogawa.a7517.R;
import com.ogawa.a7517.activity.MainActivity7517;
import com.ogawa.a7517.mqtt.MqttManager;

import java.lang.ref.SoftReference;

public class ShutdownDialog extends Dialog implements View.OnClickListener {
    private SoftReference<MainActivity7517> activity;

    public ShutdownDialog(@NonNull Context context) {
        super(context);
        if (context instanceof MainActivity7517) {
            activity = new SoftReference<>((MainActivity7517) context);
        }
        setContentView(R.layout.dialog_shutdown);
        getWindow().addFlags(Window.FEATURE_NO_TITLE);
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        findViewById(R.id.tv_end_massage).setOnClickListener(this);
        findViewById(R.id.tv_end_massage_off).setOnClickListener(this);
        findViewById(R.id.iv_close).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.tv_end_massage) {
            if (activity != null) {
                activity.get().publish(Constant.RUNNING_STATUS, "4");
            }
        } else if (v.getId() == R.id.tv_end_massage_off) {
            if (activity != null) {
                activity.get().publish(Constant.RUNNING_STATUS, "0");
            }
        }
        dismiss();
    }
}
